<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:t="http://myfaces.apache.org/tomahawk" 
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Cadastro de Funcionário</title>
    </h:head>
    <ui:decorate template="/tema/padrao.xhtml">
        <ui:define name="centro">
            <t:saveState value="#{funcionarioBean.funcionario}" />
            <t:saveState value="#{funcionarioBean.funcionarios}" />
            <h:form id="form" >
                <p:panel header="Lista de Funcionarios" >
                    <p:messages />
                    <p:inputText value="#{funcionarioBean.nomeConsulta}" />
                    <p:commandButton value="Consultar" actionListener="#{funcionarioBean.consultar}" update="tabela" />
                    <p:commandButton value="Novo" action="#{funcionarioBean.novo}" ajax="false" />
                    <p:dataTable id="tabela" value="#{funcionarioBean.funcionarios}" paginator="true" var="c" emptyMessage="Sem resultado" >
                        <p:column headerText="Nome" >
                            <h:outputText value="#{c.nome}" />
                        </p:column>
                        <p:column headerText="CPF" >
                            <h:outputText value="#{c.cpf}" converter="converterCnpjCpf" />
                        </p:column>
                        <p:column headerText="Editar" >
                            <p:commandButton value="Editar" action="#{funcionarioBean.editar}" ajax="false" >
                                <f:setPropertyActionListener value="#{c}" target="#{funcionarioBean.funcionario}" />
                            </p:commandButton>
                        </p:column>
                        <p:column headerText="Excluir" >
                            <p:commandButton value="Excluir" oncomplete="confirm.show()" >
                                <f:setPropertyActionListener value="#{c}" target="#{funcionarioBean.funcionario}" />
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>
                </p:panel>
            </h:form>

            <h:form id="formConfirm" >
                <p:confirmDialog modal="true" draggable="false" appendToBody="true" closable="true" message="Deseja realmente excluir este funcionário?" header="Aviso" widgetVar="confirm" >
                    <p:commandButton value="Sim" oncomplete="confirm.hide()" actionListener="#{funcionarioBean.excluir}" update=":form:tabela" />
                    <p:commandButton value="Não" oncomplete="confirm.hide()" />
                </p:confirmDialog>
            </h:form>
        </ui:define>
    </ui:decorate>
</html>